import { createStore } from "vuex";
import type { RootState } from "./types";
import type { Module } from "vuex";

const modules = import.meta.glob("./modules/*.{js,ts}", { eager: true });

// 动态载入modules
// 模块
let storeModules: any = {};
for (const path in modules) {
  const module = modules[path];
  const defaultExport = module.default as Module<any, any>;
  let name = path.replace("./modules/", "")
    .replace(".ts", "")
    .replace(".js", "");

  storeModules[name] = defaultExport;
}

const store = createStore<RootState>({
  modules: storeModules,
  state: {
    systemName: "FMS货运管理系统",
    AccountMode: "userBindEmployee",
    // 费用信息板块下的收入信息
    dataCopyFeeIn: [],
    // 费用信息板块下的支出信息
    dataCopyFeeOut: []
  }
});

export default store;